﻿using System;
namespace Producers.Ehr.Xtee.Riik.Ee.Producer.Ehr {
    
    
    [global::Xtee.Core.Attributes.XmlTypeAttribute(Name="EN_EhitiseOtsing_query", Namespace="http://producers.ehr.xtee.riik.ee/producer/ehr", Target=typeof(ENEhitiseOtsingQuery))]
    public class ENEhitiseOtsingQuerySerializer : global::Xtee.Core.Types.AbstractXteeSerializable {
        
        protected IENEhitiseOtsingQuery clazz;
        
        public ENEhitiseOtsingQuerySerializer(IENEhitiseOtsingQuery clazz) {
            this.clazz = clazz;
        }
        
        public override void WriteXml(global::Xtee.Core.IXteeXmlWriter Writer) {
            base.WriteXml(Writer);
            if (clazz.EhrKood!=null) {
                Writer.WriteStartElement("ehr_kood");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.EhrKood))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.Nimetus!=null) {
                Writer.WriteStartElement("nimetus");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "string");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdString(((string)(clazz.Nimetus))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.AadressId!=null) {
                Writer.WriteStartElement("aadress_id");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.AadressId))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.IsikId!=null) {
                Writer.WriteStartElement("isik_id");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.IsikId))).ToString());
                Writer.WriteEndElement();
            }
            if (clazz.KaykId!=null) {
                Writer.WriteStartElement("kayk_id");
                Writer.WriteTypeAttribute("http://www.w3.org/2001/XMLSchema", "integer");
                Writer.WriteString(new global::Xtee.Core.Schema.XsdInteger(((decimal)(clazz.KaykId))).ToString());
                Writer.WriteEndElement();
            }
        }
        
        public override void ReadXml(global::Xtee.Core.IXteeXmlReader Reader) {
            base.ReadXml(Reader);
        START:
            if ((Reader.LocalName == "ehr_kood")) {
                goto ehr_kood;
            }
            else {
                if ((Reader.LocalName == "nimetus")) {
                    goto nimetus;
                }
                else {
                    if ((Reader.LocalName == "aadress_id")) {
                        goto aadress_id;
                    }
                    else {
                        if ((Reader.LocalName == "isik_id")) {
                            goto isik_id;
                        }
                        else {
                            if ((Reader.LocalName == "kayk_id")) {
                                goto kayk_id;
                            }
                            else {
                                return;
                            }
                        }
                    }
                }
            }
        ehr_kood:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>EN_EhitiseOtsing_query>ehr_kood");
            }
            clazz.EhrKood = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("ehr_kood")).Value;
            goto START;
        nimetus:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>EN_EhitiseOtsing_query>nimetus");
            }
            clazz.Nimetus = new global::Xtee.Core.Schema.XsdString(Reader.ReadElementString("nimetus")).Value;
            goto START;
        aadress_id:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>EN_EhitiseOtsing_query>aadress_id");
            }
            clazz.AadressId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("aadress_id")).Value;
            goto START;
        isik_id:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>EN_EhitiseOtsing_query>isik_id");
            }
            clazz.IsikId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("isik_id")).Value;
            goto START;
        kayk_id:
            if (Reader.IsElementNil()) {
                throw new global::Xtee.Core.Exceptions.NillableNotAllowedException(">>EN_EhitiseOtsing_query>kayk_id");
            }
            clazz.KaykId = new global::Xtee.Core.Schema.XsdInteger(Reader.ReadElementString("kayk_id")).Value;
            goto START;
        }
    }
}
